package com.dgut.courses_selecting_sys.controller;

import com.dgut.courses_selecting_sys.entity.Role;
import com.dgut.courses_selecting_sys.entity.User;
import com.dgut.courses_selecting_sys.entity.UserRole;
import com.dgut.courses_selecting_sys.service.IRoleService;
import com.dgut.courses_selecting_sys.service.IUserRoleService;
import com.dgut.courses_selecting_sys.service.IUserService;
import com.dgut.courses_selecting_sys.utils.ShiroUtils;
import com.dgut.courses_selecting_sys.utils.core.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
public class IndexController {

    @Autowired
    IRoleService roleService;
    @Autowired
    IUserRoleService userRoleService;
    @Autowired
    IUserService userService;


    @GetMapping("/index")
    public String index(HttpServletRequest request, HttpServletResponse response, HttpSession session)
    {
        User user=userService.selectUserByLoginName(ShiroUtils.getSysUser().getLoginName());
        UserRole userRole=userRoleService.getDataByUserId(user.getUserId());
        Role role=roleService.getDataByRoleId(userRole.getRoleId());
        session.setAttribute("user", user);
        session.setAttribute("role",role);
        return "index";
    }

}
